﻿using Microsoft.AnalysisServices.AdomdClient;
using Powerless_View.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Powerless_View.Controllers.Actions
{
    public class RenderEditActionResult : ActionResult
    {
        private string _reportPath;

        public RenderEditActionResult(string progressiveSessionId)
            : base()
        {
            _reportPath = progressiveSessionId;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            //Get restult
            var getter = new HttpGetter();
            var reportContents = getter.GetResponse(_reportPath);

            context.HttpContext.Response.ContentType = "application/progressive-report";

            using(var reportStream = new MemoryStream())
            using (var reportStreamWriter = new BinaryWriter(reportStream))
            {
                //create result - manually create the response elements
                //reportStreamWriter.Write("sessionId");
                //reportStreamWriter.Write("8fe51a94b919c421380a57093caecb725t5npau2msyh1t3eyhu11hfje");
                //reportStreamWriter.Write("rpds");
                reportStreamWriter.Write(reportContents.ToArray());

                context.HttpContext.Response.BinaryWrite(reportStream.ToArray());
            }
        }
    }
}